Skip to content

fix(sma, sma_pv): read the inverter again after a silent start (2.2.2, 1.1.3) - #310

Open
frahlg wants to merge 1 commit into
mainfrom
fix/sma-wake
Open

frahlg wants to merge 1 commit into
mainfrom
fix/sma-wake

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

sma 2.2.1 and sma_pv 1.1.2 read every register through probe_read, which leaves a register alone until restart after three misses. An inverter asleep when FTW started, or held by another Modbus client, used up every try while answering nothing. The driver then sent nothing; Core reloads a driver with nothing left to read only if an earlier read had succeeded, so it stayed silent until FTW restarted it.

sma_pv also ran probe_capabilities() once, on the first poll, whatever the inverter answered. A silent first poll settled "no meter" and the fallback lifetime register (30529) for the whole run, and a refused 30513 at that moment did the same.

A register that did not answer was sent as zero (sma 26, sma_pv 21 counts in the invented-number baseline).

Change

Both drivers, one PR because they share the register map and the meter code:

  • A miss counts only in a poll where another read answered, so a silent inverter uses up no tries and is read again on the first poll it answers. A register that misses three times on an inverter that does answer is asked again every five minutes instead of never.
  • A field whose register did not answer is left out. PV and meter go out only when their power answered (30775, 30885); sma's battery only when both 30843 and 30851 did, since its power is V × A. SMA's NaN sentinels still read as 0, as before; temperatures that answer NaN are left out, now in sma_pv too.
  • The serial is read last, once the inverter has answered in that poll.
  • sma_pv: the meter is decided on every poll from 30885 (all-0xFFFF means none, as before). The lifetime counter is 30513, or 30529 while 30513 answers NaN or has been given up; a given-up 30513 is asked again every five minutes. The curtailment release ceiling (40915) is sampled once, in the first poll where PV power answered. has_meter, lifetime_reg and probe_capabilities are gone.
  • Both leave invented-number-baseline.json.

Test evidence

  • test_sma_wakes.py, twelve tests; ten fail on the old drivers and all pass now (the other two guard behaviour that already worked: no meter on an inverter without one, and the NaN fallback to 30529):
    • test_wakes_after_silence.lua (shared with fix(saj): read the serial and battery again after the inverter wakes (1.3.1) #301) for both drivers. Old sma: asleep at start-up: register 30513 not read after the device answered; old sma_pv: asleep at start-up: no meter emitted after the device answered;
    • sma_pv finds its meter after a silent start, and reads 30529 after 30513 is refused three times, asking 30513 again five minutes later;
    • PV, battery and meter left out when their power does not answer, and other fields when theirs do not.
  • make test-driver ID=sma (matches both): 235 passed, 26 skipped.
  • make absent-register-report for both: every address settles.
  • make invented-number-report for both: none.
  • make check: 5586 passed, 927 skipped.

Not yet verified

  • No hardware run. sma_pv is marked tested on four Sunny Tripowers; the meter and lifetime changes should be watched on one, ideally started while it is asleep.
  • invented-number-baseline.json and CHANGELOG.md are touched by the other driver PRs in this series; whichever merges later needs a rebase there.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move.

🤖 Generated with Claude Code

…, 1.1.3)

Every read went through a guard that left a register alone until restart
after three misses. An inverter asleep at start-up, or held by another
Modbus client, used up every try while answering nothing, and the driver
then sent nothing until FTW restarted it. sma_pv also settled on its first
poll whether a meter is paired and which lifetime register to read, so the
same start left it without a meter for the whole run. A register that did
not answer was sent as zero.

A miss now counts only in a poll where another read answered, and a
register that misses three times on an inverter that does answer is asked
again every five minutes. sma_pv decides the meter on every poll from
30885, falls back to the lifetime counter at 30529 only while 30513
answers NaN or has been given up, and samples the release ceiling in the
first poll where PV power answered. A field whose register did not answer
is left out; PV and meter go out only when their power answered, the
battery only when its voltage and current did. SMA's NaN still reads as 0.
The serial is read last, once the inverter has answered in that poll.

test_sma_wakes.py: ten of its twelve tests fail on the old drivers (the
other two guard what already worked) and all pass now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T18:51:53.633505Z d81f2f0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d81f2f0ad8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread drivers/lua/sma_pv.lua
if i32_valid(v) then mppt1_a = v * 0.001 end
local pv_w = read_i32(30775)

if not release_probed and pv_w ~= nil then probe_release() end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Capture the release ceiling before accepting curtailment

If the initial polls cannot read PV power, release_probed now stays false while driver_command("curtail", ...) can still write a setpoint. When PV power subsequently answers, this probe captures the driver's own curtailment as the natural ceiling, so curtail_disable, the watchdog and cleanup all restore the curtailed value instead of releasing it. Using the Lua harness with a 50,000 W initial ceiling, one failed PV-power read and an intervening 10,000 W curtailment, the parent restores 50,000 W but this commit restores only 10,000 W. Capture the original ceiling before accepting a curtailment, or prevent the deferred probe from sampling an active curtailment.

AGENTS.md reference: AGENTS.md:L39-L42

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant